from rest_framework.viewsets import ModelViewSet
from meiduo_admin.my_paginate import MyPageNumberPagination
from goods.models import SpecificationOption
from meiduo_admin.serializer import spu_specs_options_serializer
from rest_framework.generics import ListAPIView


class SPUSpecsOptionsSpecView(ModelViewSet):
    pagination_class = MyPageNumberPagination
    serializer_class = spu_specs_options_serializer.SPUSpecsOptionsSpecSerializer
    queryset = SpecificationOption.objects.all()


class SPUSpecView(ListAPIView):
    serializer_class = spu_specs_options_serializer.SPUSpecSerializer

    def get_queryset(self):
        queryset = SpecificationOption.objects.all()
        for spu_spec in queryset:
            spu_spec.name = "%s-%s"%(spu_spec.spu.name,spu_spec.name)
        return queryset
